package net.maku.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import net.maku.bean.query.WebTradeRecordQuery;
import net.maku.bean.vo.WebTradeRecordVO;
import net.maku.convert.WebTradeRecordConvert;
import net.maku.entity.WebTradeRecordEntity;
import net.maku.mapper.WebTradeRecordMapper;
import net.maku.service.WebTradeRecordService;
import net.maku.utils.PageResult;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 点数使用记录表
 *
 * @author 阿沐 babamu@126.com
 * @since 1.0.0 2024-09-02
 */
@Service
@AllArgsConstructor
public class WebTradeRecordServiceImpl extends BaseServiceImpl<WebTradeRecordMapper, WebTradeRecordEntity> implements WebTradeRecordService {

    @Override
    public PageResult<WebTradeRecordVO> page(WebTradeRecordQuery query) {
        IPage<WebTradeRecordEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));

        return new PageResult<>(WebTradeRecordConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }

    private LambdaQueryWrapper<WebTradeRecordEntity> getWrapper(WebTradeRecordQuery query){
        LambdaQueryWrapper<WebTradeRecordEntity> wrapper = Wrappers.lambdaQuery();
        return wrapper;
    }

    @Override
    public void save(WebTradeRecordVO vo) {
        WebTradeRecordEntity entity = WebTradeRecordConvert.INSTANCE.convert(vo);

        baseMapper.insert(entity);
    }

    @Override
    public void update(WebTradeRecordVO vo) {
        WebTradeRecordEntity entity = WebTradeRecordConvert.INSTANCE.convert(vo);

        updateById(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        removeByIds(idList);
    }

}